<template>
  <div class="my-header-top">
    <div class="wrapper">
      <i class="my-icon" @click="handleClick" :class="!state.isCollapse ? 'iconfont icon-caidan-close' : 'iconfont icon-caidan-dakai'"></i>
    </div>
    <h2 class="page-name">{{menuAllList[route.path]}}</h2>
    <div class="user-info">
      <i class="el-icon-full-screen" @click="fullGreen"></i>
      <div class="user">
        <el-dropdown>
          <span class="el-dropdown-link user">
            <i class="iconfont icon-yonghu user-icon"></i>
            <span class="user-name">{{ state.userName }}</span>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import menuAllList from '../../config/project-base/routerName'
import { useRoute } from "vue-router"
import { reactive } from 'vue';
import mitter from '../../config/third-plugins/eventBus'
interface myHeadTop {
  isCollapse:boolean,
  userName:any
}

const state = reactive<myHeadTop>({
  isCollapse: false,
  userName: localStorage.getItem('userName')
})

const route = useRoute()

const router = useRouter()

const handleClick = () => {
  state.isCollapse = !state.isCollapse
  mitter.emit('menuCollapse', state.isCollapse)
}
const fullGreen = () => {}
const logout = () => {
  ElMessage({
    type: 'success',
    message: '退出成功'
  })
  localStorage.clear()
  localStorage.setItem('tokenName', 'system')
  router.push('login')
}
</script>

<style lang="scss" scoped>
.my-header-top {
  height: 50px;
  background-color: #fff;
  border-bottom: 1px solid #eee;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 0 10px;
  .wrapper {
    display: flex;
    height: 50px;
    align-items: center;
  }
  .page-name {
    font-size: 18px;
    font-weight: 700;
  }
  .my-icon::before {
    font-size: 22px;
    cursor: pointer;
    margin-right: 10px;
    font-weight: 700;
  }
  .user-info {
    position: relative;
    display: flex;
    align-items: center;
    height: 50px;
    .el-icon-full-screen::before {
      font-size: 20px;
      font-weight: bolder;
      cursor: pointer;
      margin-right: 15px;
    }
    .user {
      display: flex;
      align-items: center;
      height: 50px;
      cursor: pointer;
      .user-icon {
        margin-right: 10px;
        border-radius: 50%;
        border: 2px solid #333;
        width: 24px;
        height: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        .el-icon-user {
          font-size: 17px;
          font-weight: bolder;
        }
      }
      .user-name {
        font-size: 17px;
      }
    }
  }
}
</style>